<?php
    include('./config.php');
    include('./request.php');
    $username = $result->username;
    $password = $result->password;  
    $user_type = $result->login_type;
    try{
        $pdo = new PDO($dsn,$user,$pass);
        if($user_type=="p"){
        $sql = "select * from user where user_name='".$username."' and user_password='".$password."'";
        $sql2 = "select market_name,market_type,market_author,market_email,market_phone from market where market_name=(select market_name from market,user,supermarket where user.user_id=supermarket.user_id and user.user_name = '".$username."')"; 
        $res = $pdo->prepare($sql);
        $res->execute();
        // $res2=$pdo->prepare($sql2);
        // $res2->execute();
        $rea = $res->fetch(PDO::FETCH_ASSOC);
        // $rea2=$res2->fetch(PDO::FETCH_ASSOC);
        if($rea['user_name']==$username && $rea['user_password']==$password){
            // if($res2){
            //     $arr = array('username'=>$rea['user_name'],'phone'=>$rea['user_phone'],'email'=>$rea['user_email'],'marketName'=>$res2['market_name'],'marketType'=>$res2['market_type'],'marketAuthor'=>$res2['market_author'],'marketEmail'=>$res2['market_email'],'marketPhone'=>$res2['market_phone']);
            //     echo json_encode($arr);
            // }else{
                $arr = array('user_id'=>$rea['user_id'],'username'=>$rea['user_name'],'phone'=>$rea['user_phone'],'email'=>$rea['user_email'],'marketName'=>"",'marketType'=>"",'marketAuthor'=>"",'marketEmail'=>"",'marketPhone'=>"");
                echo json_encode($arr);
            // }
        }else{
            echo "用户名或密码错误";
        }
    }else if($user_type=="m"){
        $sql = "select * from manager where man_name='".$username."' and man_password='".$password."'";
        $res = $pdo->prepare($sql);
        $res->execute();
        $rea = $res->fetch(PDO::FETCH_ASSOC);
        if($rea['man_name']==$username && $rea['man_password']==$password){
                $arr = array('user_id'=>$rea['man_id'],'username'=>$rea['man_name'],'phone'=>$rea['man_phone'],'email'=>$rea['man_email'],'marketName'=>"",'marketType'=>"",'marketAuthor'=>"",'marketEmail'=>"",'marketPhone'=>"");
                echo json_encode($arr);
        }else{
            echo "用户名或密码错误";
        }
    }else{
        echo "用户名或密码错误";
    }
    }catch(PDOException $e){
        echo "没有此用户";
    }
?>